//
//  RACSignal+ADMap.m
//  ADKit
//
//  Created by duzexu on 2017/12/1.
//  Copyright © 2017年 duzexu. All rights reserved.
//

#import "RACSignal+ADMap.h"
#import "YYModel.h"

#define ADSignalObjectKey @"ADSignalObjectKey"

@implementation RACSignal (ADMap)

- (RACSignal *)mapArray:(Class)cls {
    return [self map:^id(id value) {
        return [NSArray yy_modelArrayWithClass:cls json:value];
    }];
}

- (RACSignal *)mapModel:(Class)cls {
    return [self map:^id(id value) {
        return [cls yy_modelWithJSON:value];
    }];
}

@end

@implementation RACSignal (Request)

- (void)setObject:(id)object {
    [self setAssociateValue:object withKey:ADSignalObjectKey];
}

- (id)object {
    return [self getAssociatedValueForKey:ADSignalObjectKey];
}

@end

@implementation RACCommand (ADUtils)

- (RACSignal *)sucessSignal {
    return self.executionSignals.switchToLatest.deliverOnMainThread;
}

- (RACSignal *)errorSignal {
    return self.errors.deliverOnMainThread;
}

@end
